﻿using System;
using System.Web;
using System.Data;
using VIT.DataHelper;

namespace VIT.Provider
{
    public class Permission
    {
        #region Variable
        public string User { get; set; }
        public string Permissions { get; set; }
        #endregion

        #region Constructor
        public Permission()
        {
            this.User = HttpContext.Current.Session["userName"].ToString();
            this.Permissions = HttpContext.Current.Session["userPermission"].ToString();
        }

        public Permission(string userName, string userPermission)
        {
            this.User = userName;
            this.Permissions = userPermission;
        }
        #endregion

        #region Methods
        public bool CheckPermission(string func)
        {
            string[] funcs = this.Permissions.Split(',');
            foreach (string f in funcs)
                if (f == func) return true;
            return false;
        }

        public void SetPermission(string userName, string userPermission)
        {
            HttpContext.Current.Session["userName"] = User;
            HttpContext.Current.Session["userPermission"] = userPermission;
        }
        #endregion
    }
}
